package cn.gjculture.shopping.api.export;

import cn.gjculture.shopping.api.entity.Customer;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Row;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.Arrays;

@Slf4j
@Component
public class CustomerExportExcel extends ExportExcel<Customer> {
    @Override
    public void addData() {
        if (CollectionUtils.isEmpty(getDatas())) return;
        int y = getPosition()[1];
        for (Customer o : getDatas()) {
            if (o==null) continue;
            Row row = this.sheet.createRow(y++);
            row.createCell(0).setCellValue(o.getId());
            row.createCell(1).setCellValue(o.getNickname());
            row.createCell(2).setCellValue(o.getPhone());
            row.createCell(3).setCellValue(o.getOpenid());
            row.createCell(4).setCellValue(o.getLevel().toString());
            row.createCell(5).setCellValue(o.getScore().toString());
            row.createCell(6).setCellValue(o.getCountry());
            row.createCell(7).setCellValue(o.getProvince());
            row.createCell(8).setCellValue(o.getCity());
            row.createCell(9).setCellValue(o.getLanguage());
            row.createCell(10).setCellValue(o.getCustomerNo().toString());
            if(o.getJiang()==null){
                row.createCell(11).setCellValue("0");
            }else{
                row.createCell(11).setCellValue(o.getJiang().toString());
            }

        }
        this.setPosition(new int[]{0, 0});
    }

    @Override
    public void addTitle() {
        String[] titles = {"ID", "昵称", "电话", "OpenId", "会员等级","积分", "国家", "省", "市", "语言","会员编号", "购物券"};
        this.setTitles(Arrays.asList(titles));
    }

}
